/*
*    Phantom Test Driver v2.0 GUI Automation Software
*    Copyright (C) 2009  John C. Van Arsdall (john@phantomtest.com)
*
*    This program is free software; you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation; either version 2 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License along
*    with this program; if not, write to the Free Software Foundation, Inc.,
*    51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*
*/
/*
 * PTDRemotePanel.java
 *
 * Created on August 26, 2008, 1:42 PM
 */

package ptd;

import javax.swing.JLabel;

/**
 *
 * @author  John
 */
public class PTDRemotePanel extends javax.swing.JPanel {

    PTDMain pW;
    
    java.awt.GridBagConstraints EmptyConstraints = new java.awt.GridBagConstraints();
    JLabel EmptyLabel = new JLabel();
    /** Creates new form PTDRemotePanel */
    public PTDRemotePanel(PTDMain P) {
        pW = P;
        initComponents();
        DisposeAllButton.setText("Dispose All");
        StopAllButton.setText("Stop All");
        TitleLabel.setText("Remote Runs");
        
        
        EmptyConstraints = new java.awt.GridBagConstraints();
        EmptyConstraints.gridy = java.awt.GridBagConstraints.RELATIVE;
        EmptyConstraints.gridx = 0;
        EmptyConstraints.fill = java.awt.GridBagConstraints.BOTH;
        EmptyConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        EmptyConstraints.gridheight = 1;
        EmptyConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        EmptyConstraints.weightx = 1.0;
        EmptyConstraints.weighty = 1.0;
        
        ListPanel.add(EmptyLabel, EmptyConstraints);
    }

    public void addMachine(PTDRemoteMachine Machine){

        PTDMachinePanel aPanel = new PTDMachinePanel();
        aPanel.setMachine(Machine);
        
        java.awt.GridBagConstraints gridBagConstraints;

        
        ListPanel.remove(EmptyLabel);
        
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridy = java.awt.GridBagConstraints.RELATIVE;
        gridBagConstraints.gridx = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.gridheight = 1;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.weighty = 0.0;
        ListPanel.add(aPanel, gridBagConstraints);
        ListPanel.add(EmptyLabel, EmptyConstraints);
        
        
    }
    
    
    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        java.awt.GridBagConstraints gridBagConstraints;

        StopAllButton = new javax.swing.JButton();
        DisposeAllButton = new javax.swing.JButton();
        TitleLabel = new javax.swing.JLabel();
        Scroller = new javax.swing.JScrollPane();
        ListPanel = new javax.swing.JPanel();

        setLayout(new java.awt.GridBagLayout());

        StopAllButton.setToolTipText("Stop all runs");
        StopAllButton.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        StopAllButton.setMaximumSize(new java.awt.Dimension(100, 7));
        StopAllButton.setMinimumSize(new java.awt.Dimension(100, 7));
        StopAllButton.setPreferredSize(new java.awt.Dimension(100, 7));
        StopAllButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                StopAllButtonActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipadx = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        add(StopAllButton, gridBagConstraints);

        DisposeAllButton.setToolTipText("Dispose all runs from list");
        DisposeAllButton.setBorder(new javax.swing.border.SoftBevelBorder(javax.swing.border.BevelBorder.RAISED));
        DisposeAllButton.setMaximumSize(new java.awt.Dimension(100, 7));
        DisposeAllButton.setMinimumSize(new java.awt.Dimension(100, 7));
        DisposeAllButton.setPreferredSize(new java.awt.Dimension(100, 7));
        DisposeAllButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                DisposeAllButtonActionPerformed(evt);
            }
        });
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 1;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipadx = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        add(DisposeAllButton, gridBagConstraints);

        TitleLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        TitleLabel.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 2;
        gridBagConstraints.gridy = 0;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.ipadx = 4;
        gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
        gridBagConstraints.weightx = 1.0;
        gridBagConstraints.insets = new java.awt.Insets(4, 4, 4, 4);
        add(TitleLabel, gridBagConstraints);

        ListPanel.setLayout(new java.awt.GridBagLayout());
        Scroller.setViewportView(ListPanel);

        gridBagConstraints = new java.awt.GridBagConstraints();
        gridBagConstraints.gridx = 0;
        gridBagConstraints.gridy = 1;
        gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
        gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
        gridBagConstraints.weighty = 1.0;
        add(Scroller, gridBagConstraints);
    }// </editor-fold>//GEN-END:initComponents

private void StopAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StopAllButtonActionPerformed
    int cnt = ListPanel.getComponentCount();
    for(int i = 0; i < cnt; i++){
        if(ListPanel.getComponent(i) instanceof PTDMachinePanel){
            PTDMachinePanel P = (PTDMachinePanel)ListPanel.getComponent(i);
            P.stopMe();
        }
    }
}//GEN-LAST:event_StopAllButtonActionPerformed

private void DisposeAllButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DisposeAllButtonActionPerformed
    int cnt = ListPanel.getComponentCount();
    for(int i = 0; i < cnt-1; i++){
        if(ListPanel.getComponent(0) instanceof PTDMachinePanel){
            PTDMachinePanel P = (PTDMachinePanel)ListPanel.getComponent(0);
            P.disposeMe();
        }
    }
}//GEN-LAST:event_DisposeAllButtonActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton DisposeAllButton;
    private javax.swing.JPanel ListPanel;
    private javax.swing.JScrollPane Scroller;
    private javax.swing.JButton StopAllButton;
    private javax.swing.JLabel TitleLabel;
    // End of variables declaration//GEN-END:variables

}
